package com.xiaoyin.community.Service;

import com.xiaoyin.community.Domain.Candicate;
import com.xiaoyin.community.Repository.CandicateRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by yinjianping@baidu.com on 2018/7/11.
 *
 * @Description:
 * @Modified By:
 */
@Service
public class CandicateService {
    @Autowired
    private CandicateRepository candicateRepository;

    //所有
    public List<Candicate> findAllService(){
        return candicateRepository.findAll();
    }

    //按照id查一个
    public Candicate findOneService(Integer id){
        return candicateRepository.findById(id).orElse(null);//如果没有查到return null
    }

    //按照name查
    public List<Candicate> findByNameService(String name){
        return candicateRepository.findByCandicateName(name);
    }

    //添加一个
    public Candicate saveService(Candicate candicate){
        return candicateRepository.save(candicate);
    }

    //按照name和班级
    public List<Candicate> findByNameAndClassService(String name,String candicateClass){
        return candicateRepository.findByCandicateNameAndCandicateClass(name,candicateClass);
    }

    //按照name或是phone
    public List<Candicate> findByNameOrPhoneService(String name,String phone){
        return candicateRepository.findByCandicateNameOrCandicatePhone(name,phone);
    }
}
